mapview is intended to provide a quick and easy way to visualize/plot spatial data in an interactive manner. As such, a one-liner is enough to produce an interactive map view of the data. Methods are defined for all objects from packages sf, sp, raster and satellite.
mapview includes 3 vector type data sets:
breweries - a selection of (micro-) breweries in Franconia, Bavaria.trails - slected hiking trails in Franconia.franconia - administrative regions of Franconia at the district level.For vector data a call to mapview without any further arguments will produce a default map view including:
Here’s an example for each vector type:
If we only want to plot certain columns of the attribute table we can use argument zcol. Each column will be rendered as a separate layer. These layers will be colored according to the selected attributes.
mapview(breweries, zcol = c("brewery", "village", "founded"))We can also include legends for the layers. Be careful, though, as it is currently not possible to link legends to layers so we end up with too many legends to fit the viewer window if we want to visualize many layers. This is also the reason why legends are not shown by default.
mapview(breweries, zcol = "founded", legend = TRUE)mapview includes 3 raster type data sets:
elevation - a digital elevation model of Franconiapoppendorf - a RasterBrick including 5 bands of a landsat scene located in FranconiakiliNDVI - a raw multiband raster data set of 23 16-day Aqua-MODIS NDVI layers of Mt. Kilimanajro in Tanzania for the year 2013. See Detsch et al. 2016 for details on how this data set was createdHere’s an example for each raster type (including a sp::SpatialPixelsDataFrame):
mapview(elevation)This will produce one map view layer for each layer in the stack/brick. Use the layers control to switch between the layers. By default all layers are shown (see chapter advanced for an example on how to hide all but one layer).
mapview(poppendorf)Depending on the number of attribute columns, this is either rendered as a RasterLayer or RasterBrick.
library(mapview)
library(raster)
library(sp)
# SpatialPixelsDataFrame
data(meuse.grid)
coordinates(meuse.grid) <- ~x+y
proj4string(meuse.grid) <- CRS("+init=epsg:28992")
gridded(meuse.grid) <- TRUE
mapView(meuse.grid)Similar to the vector data functionality, if we want to render a certain column of the attribute table, we can use the zcol argument
library(mapview)
library(raster)
library(sp)
# SpatialPixelsDataFrame
data(meuse.grid)
coordinates(meuse.grid) <- ~x+y
proj4string(meuse.grid) <- CRS("+init=epsg:28992")
gridded(meuse.grid) <- TRUE
mapView(meuse.grid, zcol = "soil")Identical to vector data plots use legend = TRUE to add legend(s) to raster visualizations.
mapview(elevation, legend = TRUE)